#include "RequestHandler.h"

#include "../Core/Log.h"
#include "../Shared/Application.h"
#include "../Shared/Configuration.h"
#include "MessageReceiver.h"
#include "../Shared/Message.h"

RequestHandler::RequestHandler()
{
    ///Parse config
    Configuration::GetSingleton().ParseFile(REQUESTHANDLERCONFIG);

    ///Application init
    Application::GetSingleton().ApplicationId = 1;
	Application::GetSingleton().ApplicationName = Configuration::GetSingleton().GetString("ApplicationName");
	Application::GetSingleton().State = ApplicationState_OnlineUnary;

	///Log init
	Log::GetSingleton().GetLogFile().SetFileNameMask(REQUESTHANDLERLOG);
	Log::GetSingleton().GetLogFile().SetInterval(LogFileInterval_EveryDay);
	Log::GetSingleton().SetWriteToLogFile(true);
	Log::GetSingleton().SetWriteToCOut(true);

	Log::GetSingleton().Write(LogLevel_Critical, "================================================");
	Log::GetSingleton().Write(LogLevel_Critical, "|Starting RequestHandler                        |");
	Log::GetSingleton().Write(LogLevel_Critical, "================================================");
}

void RequestHandler::Main() {
    RawData t;
    t.FromString("101\n100\n\nKarol-Danutama\n1111\nLX-Dispatcher\nMenanam-Pohon\nBatch\nTest\n1000\n16000000\n");

    MessageReceiver::GetSingleton().ProcessMessage(t);

    MessageReceiver::GetSingleton().Join();
}

RequestHandler::~RequestHandler()
{
    //dtor
}
